package com.wq.qa.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wq.qa.entity.Problem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProblemMapper extends BaseMapper<Problem> {
    @Select(value = "select * from tb_problem tp join tb_pl tpl ON tp.id=tpl.problemid where tpl.labelid=#{labelid} ORDER BY tp.createtime DESC LIMIT #{start},#{size}")
    List<Problem> findLatestProblems(@Param("labelid") String labelid, @Param("start") int start, @Param("size") int size);

    @Select(value = "SELECT COUNT(1) from tb_problem tp join tb_pl tpl ON tp.id=tpl.problemid where tpl.labelid=#{labelid}")
    long total(@Param("labelid") String labelid);

    @Select(value = "select * from tb_problem tp join tb_pl tpl ON tp.id=tpl.problemid where tpl.labelid=#{labelid} ORDER BY tp.reply DESC LIMIT  #{start},#{size}")
    List<Problem> findHotProblems(@Param("labelid") String labelid, @Param("start") int start, @Param("size") int size);

    @Select(value = "select * from tb_problem tp join tb_pl tpl ON tp.id=tpl.problemid where tpl.labelid=#{labelid} and tp.reply=0  ORDER BY tp.createtime DESC #{start},#{size}")
    List<Problem> findWaitProblems(@Param("labelid") String labelid, @Param("start") int start, @Param("size") int size);

    @Select(value = "SELECT COUNT(1) from tb_problem tp join tb_pl tpl ON tp.id=tpl.problemid where tpl.labelid=#{labelid} and tp.reply=0")
    long waitTotal(@Param("labelid") String labelid);
}
